/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.amuthu.expression.function.indicator;

import org.amuthu.DataStore;
import org.amuthu.expression.Expression;
import org.amuthu.parser.ExpressionVisitor;

/**
 *
 * @author prabhus
 */
public abstract class BollingerFunction extends BaseIndicatorFunction
{
   private double deviation;

   public double getDeviation()
   {
      return deviation;
   }

   public void setDeviation(double deviation)
   {
      this.deviation = deviation;
   }

   @Override
   public boolean doUpdateParameters(DataStore dataStore, Expression[] arguments, ExpressionVisitor visitor)
   {
      if (arguments.length < 2)
      {
         return false;
      }

      int period = (int) visitor.evaluate(arguments[0]);

      if (period < 0)
      {
         return false;
      }

      deviation = visitor.evaluate(arguments[1]);

      int startOffset = (arguments.length > 2) ? (int) visitor.evaluate(arguments[2]) : 0;

      setPeriod(period);
      setOffset(startOffset);

      return true;
   }
}
